package com.ticket.controller;

import com.ticket.entity.CollectCount;
import com.ticket.entity.HomePage;
import com.ticket.service.CollectService;
import com.ticket.service.ContestService;
import com.ticket.service.MovieService;
import com.ticket.service.StageService;
import com.ticket.service.impl.CollectServiceImpl;
import com.ticket.service.impl.ContestServiceImpl;
import com.ticket.service.impl.MovieServiceImpl;
import com.ticket.service.impl.StageServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 全谢民
 * @version 8.0
 * @description: TODO   前端用户首页控制器
 * @date 2023/10/12 9:03
 */
public class UserHomePageController {
    CollectService cs = new CollectServiceImpl();

    /**
     * @param request
     * @param response
     * @return java.lang.Object
     * @author 全谢民
     * @description TODO 前端首页 根据用户收藏判断
     * @date 2023/10/12 9:28
     */
    public Object homePageAll(HttpServletRequest request, HttpServletResponse response) {
        //获取用户id 存入实体类中
        int userId = Integer.parseInt(request.getParameter("userId"));
        HttpSession session = request.getSession();
        CollectCount count = new CollectCount(userId);
        CollectCount cc = cs.selCount(count);

        StageService ss = new StageServiceImpl();
        MovieService ms = new MovieServiceImpl();
        ContestService contestService = new ContestServiceImpl();


        List<HomePage> homePageStageDramaList = ss.selHomeStageList(1);
        List<HomePage> homePageStageList = ss.selHomeStageList(2);
        List<HomePage> homePageMovieList = ms.selHomeMovieList();
        List<HomePage> homePageContestList = contestService.selHomeContestList();
        Map<String, Object> listMap = new HashMap<String, Object>();
        if (cc.getContestCount() >= cc.getMovieCount() && cc.getMovieCount() >= cc.getStageCount()) {
            listMap.put("1", homePageContestList);
            listMap.put("2", homePageMovieList);
            listMap.put("3", homePageStageList);
        } else if (cc.getMovieCount() >= cc.getContestCount() && cc.getContestCount() >= cc.getStageCount()) {
            listMap.put("1", homePageMovieList);
            listMap.put("2", homePageContestList);
            listMap.put("3", homePageStageList);
        } else if (cc.getStageCount() >= cc.getContestCount() && cc.getContestCount() >= cc.getMovieCount()) {
            listMap.put("1", homePageStageList);
            listMap.put("2", homePageContestList);
            listMap.put("3", homePageMovieList);
        } else if (cc.getStageCount() >= cc.getContestCount() && cc.getMovieCount() >= cc.getContestCount()) {
            listMap.put("1", homePageStageDramaList);
            listMap.put("2", homePageMovieList);
//            listMap.put("3",homePageContestList);
            listMap.put("3", homePageStageList);
        }
        session.setAttribute("listMap", listMap);
        return "redirect:/user_page/home_page.jsp";
    }
}
